package com.zut.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zut.dao.FondDao;
import com.zut.dao.ReplyDao;
import com.zut.domain.Fond;
import com.zut.domain.Post;
import com.zut.domain.Reply;
import com.zut.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReplyServiceImpl implements ReplyService {
    @Autowired
    private ReplyDao replyDao;

    @Autowired
    private FondDao fondDao;


    public PageInfo<Reply> getAllReply(Integer pageNum, Integer pageSize) {
        List<Reply> list;
        PageHelper.startPage(pageNum, pageSize);
        list = replyDao.getAllPost();
        return new PageInfo<>(list);

    }

    public PageInfo<Map<String, String>> getAll(Integer pageNum, Integer pageSize, String postId, String userId) {
        List<Map<String, String>> list;
        PageHelper.startPage(pageNum, pageSize);
        list = replyDao.getAll(postId, userId);
        return new PageInfo<>(list);
    }

    public boolean insert(Reply reply) {
        return replyDao.insert(reply) > 0;
    }

    public boolean deleteById(String id) {
        return replyDao.deleteById(id) > 0;
    }

    public boolean update(Reply reply) {
        return replyDao.update(reply) > 0;
    }

    public boolean LikeOn(String replyId, String userId) {
        Fond fond = new Fond(replyId, userId);
        fondDao.likeOn(fond);
        return replyDao.updateLikeOn(replyId) > 0;
    }

    public boolean LikeDown(String replyId, String userId) {
        Fond fond = new Fond(replyId, userId);
        fondDao.likeDown(fond);
        return replyDao.updateLikeDown(replyId) > 0;
    }

    public List<Map<String, String>> getAllByUserId(String id) {
        List<Map<String, String>> allByUserID = replyDao.getAllByUserID(id);
        return allByUserID;
    }

    public PageInfo<Reply> getAllByPostId (Integer pageNum, Integer pageSize, String id) {
        List<Reply> list;
        PageHelper.startPage(pageNum, pageSize);
        list = replyDao.getAllByPostId(id);
        return new PageInfo<>(list);
    }


}
